﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Metadata;

namespace PureTest
{
    public class DataSource
    {
        //public const string ConnString = "XpoProvider=MSSqlServer;data source=localhost;user id=sa;password=98096;initial catalog=PureDemo;Persist Security Info=true";
        public const string ConnString = "XpoProvider=MSSqlServer;data source=192.168.1.115;user id=sa;password=sa;initial catalog=PureDemo;Persist Security Info=true";

        static public Session GetSession()
        {
            if (XpoDefault.Session != null)
            {
                XPDictionary dict = new ReflectionDictionary();
                // Initialize the XPO dictionary.
                dict.GetDataStoreSchema(typeof(OT.Module.Model.Category).Assembly);
                XpoDefault.Session = null;
                IDataStore store = XpoDefault.GetConnectionProvider(ConnString, AutoCreateOption.SchemaAlreadyExists);
                XpoDefault.DataLayer = new ThreadSafeDataLayer(dict, store);
            }

            return new Session();
        }
    }
}
